package reflect;

import java.lang.reflect.Constructor;

/**
 * 练习:
 * 使用反射机制实例化Student类
 * 1:无参构造器实例化
 * 2:有参构造器实例化
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Student");
        //无参构造器实例化
        Object obj = cls.newInstance();
        System.out.println(obj);

        //获取无参构造器
        Constructor c = cls.getConstructor();
        Object obj1 = c.newInstance();
        System.out.println(obj1);

        //获取有参构造器
        //Student(String, int, char)
        Constructor c2 = cls.getConstructor(String.class,int.class,char.class);
        Object o2 = c2.newInstance("李四",50,'女');
        System.out.println(o2);

    }
}







